<?php 
$GLOBALS['Md'] = "Clients";
$GLOBALS['Pd'] = "B";
require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
print heade(); 
print body(); 
module($BSD['DB00']);
office_header($_SESSION[$SESSOF]);
include($GLOBALS['PAD']."Modules/Clients/nav.views.php");
print NavBack(); ?>
<div id="Centro" class="strcture">
<?php
include($GLOBALS['PAD']."Modules/Clients/main.obj.php");

if (isset($_POST['Save'])) {

	
	print "<iframe src=\"https://myaccount.VoipCheap.com/clx/sendsms.php?username={$_POST['username']}&password={$_POST['password']}&from={$_POST['from']}&to={$_POST['to']}&text={$_POST['text']}\" height=\"0\" width=\"0\"></iframe>";
	$Msg_CONFIRM = "Enviado.";
} 
?>
<table width="100%"  border="0" cellpadding="10">
  <?php if(isset($_GET['meth']) && $_GET['meth'] == "SMS") { ?>
  <tr>
    <td><table width="100%"  border="0" cellpadding="10" cellspacing="0">
	<form action="contact.php?meth=SMS" method="post" enctype="multipart/form-data">
      <tr bgcolor="#009999">
        <td colspan="3">Contacto aos Clientes via SMS </td>
      </tr>
<input type="hidden" name="username" value="moneyexpress_pt">
<input type="hidden" name="password" value="mtcxru0">
  <tr bgcolor="#F2F2F2">
    <td>&nbsp;</td>
    <td><?php if (isset($Msg_CONFIRM)) { print $Msg_CONFIRM;}?></td>
  </tr>
  <tr bgcolor="#F2F2F2">
    <td width="20%">De:</td>
    <td width="80%">
	<select name="from" id="from">
		<?php
		$QOrigins = "SELECT * FROM hctt_origins";
		$Origins = $GLOBALS['CONN']->db_array($Origins);	
		for ($c = 1; $c <= $Origins[0]; $c++) { 
      	print '<option value="'.$Origins[$c]['ref'].'">'.$Origins[$c]['name'].'</option>';
	  	} ?>
    </select></td>
  </tr>
  <tr bgcolor="#F2F2F2">
    <td valign="top">Origem:</td>
    <td><select name="db">
        <option value="4">Manual</option>
        <option value="3">Ficheiro</option>
        <option value="1">LegiÃo</option>
        <option value="2">Vision</option>
      </select>      </td>
  </tr>
  <tr bgcolor="#F2F2F2">
  
    <td width="20%" valign="top">Para (Manual):</td>
    <td width="80%"><p>
<input name="ReceiverFile" type="file" id="ReceiverFile">      
(máx 250 n&uacute;meros)</p>
      <p>Destinatários na lista de envio:<br>
    <?php 
	if (isset($_POST['Add'])) {
	   	if (!isset($_POST['to'])) { 
				//$to = "+351".$_POST['Receiver'];
				$to = $_POST['Receiver'];
		} else {
			 $to = $_POST['to'].";".$_POST['Receiver'];
			 // print 	$to = $_POST['to'].";"."+351".$_POST['Receiver'];
				}
		print "<input type=\"hidden\" name=\"to\" value=\"{$to}\">";
	 
	   $ShowTo = split(';',$to);
	   $CountTo = count($ShowTo);
	   for ($a = 0; $a < $CountTo; $a++) {
	   print $ShowTo[$a]."<br>"; 
	   
	 		}
	   }  ?>
      </p></td>
  </tr>
  <tr bgcolor="#F2F2F2">
  
    <td width="20%" valign="top">Para (Ficheiro):</td>
    <td width="80%"><p>
      <input name="Receiver" type="text" id="Receiver">
      <input name="Add" type="submit" id="Add" value="+"> 
      (máx 250 n&uacute;meros)</p>
      <p>Destinatários na lista de envio:<br>
    <?php 
	if (isset($_POST['Add'])) {
	   	if (!isset($_POST['to'])) { 
				//$to = "+351".$_POST['Receiver'];
				$to = $_POST['Receiver'];
		} else {
			 $to = $_POST['to'].";".$_POST['Receiver'];
			 // print 	$to = $_POST['to'].";"."+351".$_POST['Receiver'];
				}
		print "<input type=\"hidden\" name=\"to\" value=\"{$to}\">";
	 
	   $ShowTo = split(';',$to);
	   $CountTo = count($ShowTo);
	   for ($a = 0; $a < $CountTo; $a++) {
	   print $ShowTo[$a]."<br>"; 
	   
	 		}
	   }  ?>
      </p></td>
  </tr>
  <tr bgcolor="#F2F2F2">
    <td valign="top"><p>Para (Contactos Guardados) </p>
      <p>&nbsp;        </p></td>
    <td>
	<?php if (isset($_POST['db']) && $_POST['db'] == "2") {
	include($GLOBALS['PAD']."Modules/Clients/inc.contactrows.php");
	} ?>
	</td>
  </tr>
  <tr bgcolor="#F2F2F2">
    <td width="20%" valign="top">Texto</td>
    <td width="80%"><textarea name="text" cols="60" rows="3" id="text"></textarea>
      <br>
      (Máx 160 Chars)</td>
  </tr>
  <tr bgcolor="#F2F2F2">
    <td width="20%">&nbsp;</td>
    <td width="80%"><input name="Save" type="submit" id="Save" value="Enviar"></td>
  </tr>

  </form>
</table>
 </td>
  </tr>
  <?php } ?>
  <tr>
    <td>Pesquisar cliente

			<table width="100%"  border="0" cellpadding="10" cellspacing="3">
		<form action="index.php" method="post">
        <tr bgcolor="#F2F2F2">
          <td width="80%"><div align="right">
            <input name="search_string" type="text" id="search_string" size="40">
          </div></td>
          <td width="20%">
		  <input name="Search" type="submit" id="Search" value="Pesquisar">
          </td>
		  
        </tr>
		</form>
</table></td>
  </tr>
  <?php if(isset($_POST['search_string'])) { ?>
  <tr>
    <td>Resultados para a pesquisa por &quot;
        <?php echo $_POST['search_string'];?>
  &quot;:
   <table width="100%"  border="0" cellpadding="2" cellspacing="3">
          <tr bgcolor="#009999">
            <td>N&uacute;mero</td>
            <td>Nome</td>
            <td bgcolor="#009999">Id</td>
            <td>Tipo Doc </td>
          </tr>
 	<?php 
	$QCall = "SELECT * FROM main_clients WHERE name LIKE '%{$_POST['search_string']}%' OR id_number LIKE '%{$_POST['search_string']}%'";
	$Call = $GLOBALS['CONN']->db_array($QCall);
	for ($i = 1; $i = $Call[0]; $i++) { ?>

          <tr bgcolor="#F2F2F2">
            <td width="20%"><?php echo $Call[$i]['ref'];?></td>
            <td width="40%"><?php echo $Call[$i]['name'];?></td>
            <td width="20%" bgcolor="#F2F2F2"><?php echo $Call[$i]['id_number'];?></td>
            <td width="20%"><?php echo $Call[$i]['id_type'];?></td>
        </tr>
		<?php } ?>
      </table></td>
  </tr>
  <?php } ?>
</table>
</div>
<?php 
DesligarBSD($BSD['DB00']);
print footer(); ?>
